package com.ruoyi.controller.business;

import com.ruoyi.common.core.domain.AjaxResult;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/process")
public class ProcessTestController {

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private ProcessRuntime processRuntime;

    /**
     * 通过本地文件部署流程模型
     * @return
     */
    @GetMapping("/deployModel")
    public AjaxResult deployModel() {
        Deployment deploy = repositoryService.createDeployment().name("研究院员工离肥审批2").addClasspathResource("processes/gjy_lf.bpmn").deploy();
        System.out.println(deploy.getId());
        return AjaxResult.success();
    }

    /**
     * 获取流程模型
     * @return
     */
    @GetMapping("/getModels")
    public AjaxResult getModels() {
        List<Model> list = repositoryService.createModelQuery().list();
        for(Model model : list){
            System.out.println("Id："+model.getId());
            System.out.println("Name："+model.getName());
            System.out.println("Key："+model.getKey());
        }
        return AjaxResult.success(list);
    }

    /**
     * 获取流程部署
     * @return
     */
    @GetMapping("/getDeployments")
    public AjaxResult getDeployments() {
        List<Deployment> list = repositoryService.createDeploymentQuery().list();
        for(Deployment dep : list){
            System.out.println("Id："+dep.getId());
            System.out.println("Name："+dep.getName());
            System.out.println("DeploymentTime："+dep.getDeploymentTime());
            System.out.println("Key："+dep.getKey());
        }
        return AjaxResult.success(list);
    }
}
